<?php
require_once 'fun.php';
require_once 'push.php';

$param = file_get_contents('php://input');
$param = json_decode($param, true);

file_put_contents('notify_url.txt', $param['notify_url']);
$param['notify_url'] = 'https://ldjx.ricke.cc/api/douyin/notify.php';
$res = GetApi("https://developer.toutiao.com/api/apps/ecpay/v1/create_order", $param);
file_put_contents('cp_extra.txt', $param['cp_extra'], FILE_APPEND);
if ($param['cp_extra']) {
    $cp_extra = strToData($param['cp_extra']);
    $cp = getPush([
        "app_name" => "douyin",
        "open_id" => $cp_extra['open_id'],
        "order_detail" => json_encode([
            "order_id" => $param['out_order_no'],
            // "order_id" => $param['out_order_no'],
            "create_time" => (int) $cp_extra['create_time'],  //订单创建时间
            "status" => "待支付",
            "amount" => 1,
            "total_price" => (float) $param['total_amount'],
            "detail_url" => $cp_extra['detail_url'],
            "item_list" => [
                [
                    "item_code" => $cp_extra['item_code'],
                    "img" => $cp_extra['img'],
                    // "title" => "测试标题",
                    "title" => $cp_extra['title'],
                    "sub_title" => $cp_extra['sub_title'], //子订单商品介绍副标题
                    "amount" => 1,
                    "price" => (float) $param['total_amount']
                ]
            ]
        ]),
        "order_status" => 0,
        "order_type" => 0,
        "update_time" => time(),

    ]);
} else {
    $cp = ['code' => 1, 'msg' => 'cp_extra参数错误'];
}
// file_put_contents('cp.json', $cp);
$res = json_decode($res, true);
$res['cp'] = json_decode($cp, true);
$res['cp_extra'] = $cp_extra;
echo json_encode($res);
exit;
